#include "sort.hpp"

bool Check(std::vector<int>& array)
{
  assert(array.size());
  for(int i = 0; i < (int)array.size() - 1; i++){
    if(array[i] > array[i + 1]){
      return false;
    }
  }
  return true;
}

void CheckShellSort()
{
  std::vector<int> array;
  for(int i = 0; i < 100000; i++){
    array.push_back(rand());
  } 

  Sort::ShellSort(array); 

  if(Check(array)){
    printf("ShellSort succeed!!!\n");
  }
  else{
    printf("ShellSort fail!!!\n");
  }
}

void CheckNoRQuickSort()
{
  std::vector<int> array;
  for(int i = 0; i < 1000000; i++){
    array.push_back(rand());
  } 

  Sort::NoRQuickSort(array); 

  if(Check(array)){
    printf("NoRQuickSort succeed!!!\n");
  }
  else{
    printf("NoRQuickSort fail!!!\n");
  }
}

void CheckRQuickSort()
{
  std::vector<int> array;
  for(int i = 0; i < 1000000; i++){
    array.push_back(rand());
  } 

  Sort::RQuickSort(array); 

  if(Check(array)){
    printf("RQuickSort succeed!!!\n");
  }
  else{
    printf("RQuickSort fail!!!\n");
  }
}

void CheckSelectSort()
{
  for(int k = 1; k < 1000; k++){
    std::vector<int> array;
    for(int i = 0; i < k; i++){
      array.push_back(rand());
    } 

    Sort::SelectSort(array); 

    if(Check(array) == false){
      printf("%d SelectSort fail!!!\n", k);
      return ;
    }
  }
  printf("SelectSort succeed!!!\n");
}

void CheckInsertSort()
{
  std::vector<int> array;
  for(int i = 0; i < 10000; i++){
    array.push_back(rand());
  } 

  Sort::InsertSort(array); 

  if(Check(array)){
    printf("InsertSort succeed!!!\n");
  }
  else{
    printf("InsertSort fail!!!\n");
  }
}

void CheckBubbleSort()
{
  std::vector<int> array;
  for(int i = 0; i < 10000; i++){
    array.push_back(rand());
  } 

  Sort::BubbleSort(array); 

  if(Check(array)){
    printf("BubbleSort succeed!!!\n");
  }
  else{
    printf("BubbleSort fail!!!\n");
  }
}

void CheckRMergeSort()
{
  for(int k = 1; k < 1000; k++){
    std::vector<int> array;
    for(int i = 0; i < k; i++){
      array.push_back(rand());
    } 

    Sort::RMergeSort(array); 

    if(Check(array) == false){
      printf("RMergeSort fail!!!\n");
      return ;
    }
  }
  printf("RMergeSort succeed!!!\n");
}

void CheckNoRMergeSort()
{
  for(int k = 1; k < 1000; k++){
    std::vector<int> array;
    for(int i = 0; i < k; i++){
      array.push_back(rand() % 100 + 1);
    } 

    Sort::NoRMergeSort(array); 

    if(Check(array) == false){
      printf("%d  NoRMergeSort fail!!!\n", k);
      Sort::Print(array);
      return ;
    }
  }
  printf("NoRMergeSort succeed!!!\n");
}

void CheckHeapSort()
{
  for(int k = 1; k < 1000; k++){
    std::vector<int> array;
    for(int i = 0; i < k; i++){
      array.push_back(rand() % 100 + 1);
    } 

    Sort::HeapSort(array); 

    if(Check(array) == false){
      printf("%d  HeapSort fail!!!\n", k);
      Sort::Print(array);
      return ;
    }
  }
  printf("HeapSort succeed!!!\n");
}

int main()
{
  srand((unsigned long)time(nullptr));
  CheckRQuickSort();
  CheckSelectSort();
  CheckInsertSort();
  CheckBubbleSort();
  CheckNoRQuickSort();
  CheckShellSort();
  CheckRMergeSort();
  CheckNoRMergeSort();
  CheckHeapSort();
  return 0;
}
